/*
 * Helper class. Full of random helpful functions we got tired of typing that 
 * dont seem to fit in any one place
 */

package lwjglbase;

import java.nio.FloatBuffer;
import org.lwjgl.BufferUtils;

public class Utils {
    static FloatBuffer createFB(float[] input) {
        FloatBuffer buf = BufferUtils.createFloatBuffer(input.length);
        buf.put(input);
        buf.rewind();
        return buf;
    }
    
    static float sin(float degrees) {
        return (float)Math.sin(degrees*Math.PI/180);
    }

    static float cos(float degrees) {
        return (float)Math.cos(degrees*Math.PI/180);
    }
    
    /*
     * Splits the input string over the delimiter then parses each part to a 
     * float. similar to ruby: in.split(delim).to_f
     */
    static float[] stringToFloatArray(String in, String delim) {
        String[] strings = in.split(delim);
        float[] ret = new float[strings.length];
        for (int i = 0; i < strings.length; i++) {
            ret[i] = Float.parseFloat(strings[i]);            
        }
        return ret;
    }
}
